package cn.edu.scau.cmi.chensicheng.client;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.chensicheng.domain.Insurance;
import cn.edu.scau.cmi.chensicheng.factory.InsuranceFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SimpleFactoryMethodClient extends Application implements Initializable {

	@FXML
	private VBox vBox;
	@FXML
	private ImageView imageView;
	@FXML
	private Button button;
	@FXML
	private TextArea textArea;
	@FXML
	private ChoiceBox<String> choiceBox;

	@Override
	public void start(Stage primaryStage) throws IOException {
		vBox = FXMLLoader.load(getClass().getResource("../SimpleFactoryMethod.fxml"));
		Scene scene = new Scene(vBox);
		primaryStage.setScene(scene);
		primaryStage.setTitle("实验三简单工厂模式");
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void initialize(URL url, ResourceBundle rb) {
		imageView.setImage(new Image(getClass().getResourceAsStream("../selfie.jpg")));
		choiceBox.setValue("司机受伤");
		choiceBox.setItems(FXCollections.observableArrayList("司机受伤", "汽车损坏", "人员伤亡", "多种事故"));
		button.setOnAction(e -> {
			Insurance insurance = InsuranceFactory.getInstance(choiceBox.getValue());
			textArea.setText(insurance.toString());
		});
	}
}
